package com.myh.cc.coom.ranking.net

import com.myh.cc.base.BaseNetControl
import com.myh.cc.coom.ranking.bean.RankingBean
import com.myh.cc.coom.ranking.bean.RankingDetailsBean
import com.myh.cc.coom.ranking.net.interf.IRankingNetControl
import com.myh.cc.network.RequestCallBack
import com.myh.cc.network.request.HttpRequestImpl
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers

/**
 * des    ：
 * create    ：  mayahao.
 * date   ：  2018/1/13.   ：
 */
class RankingNetControl :BaseNetControl(), IRankingNetControl{

    override fun getRanking(callBack: RequestCallBack, header: String, map: Map<String, String>, tag: Int) {

        HttpRequestImpl.httpRequest.getRanking(header,map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : Observer<RankingBean> {


                    override fun onSubscribe(d: Disposable) {
                        disposable = d
                    }

                    override fun onNext(value: RankingBean) {
                        callBack.success(value, tag)
                    }

                    override fun onError(e: Throwable) {
                        callBack.error(e.toString(),tag)
                    }

                    override fun onComplete() {

                    }
                })
    }


    override fun getRankingDetails(callBack: RequestCallBack, header: String, map: Map<String, String>, tag: Int) {
        HttpRequestImpl.httpRequest.getRankingDetails(header,map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(object : Observer<RankingDetailsBean> {


                    override fun onSubscribe(d: Disposable) {
                        disposable = d
                    }

                    override fun onNext(value: RankingDetailsBean) {
                        callBack.success(value, tag)
                    }

                    override fun onError(e: Throwable) {
                        callBack.error(e.toString(),tag)
                    }

                    override fun onComplete() {

                    }
                })
    }
}